import React, {Component} from 'react';
import {StyleSheet, Text, View, TouchableOpacity} from 'react-native';
import { NativeModules,NativeEventEmitter,Platform } from 'react-native';

var plugin = NativeModules.T11Plugin;

var NativeNotificationMoudule = new NativeEventEmitter(plugin);
var subscription;
var subResultForUpload;

export default class T11Plugin extends Component{
    constructor(props, context) {
        super(props, context);
        this.state = {};

    }
    componentWillMount() {
        console.log('开始订阅通知...');
        if (Platform.OS === 'ios') {
            subscription = NativeNotificationMoudule.addListener(
                'EventReminder_BarcodeScanSuccessForRN',
                (reminder) => {
                    const qrCode = reminder.qrCode;
                    const error = null;
                    this.props.callback(qrCode,error);
                }
            );

            subResultForUpload = NativeNotificationMoudule.addListener(
                'EventReminder_ResultForUpload',
                (reminder)=>{
                    const success = reminder.success;
                    const error = reminder.error;
                    this.props.callback(success,error);
                }
            );
        } else {

        }
    }
    render(){
        this.props.type[1]();
        switch(this.props.type[0].toLowerCase()){
            case "scan".toLowerCase():
                plugin.scan && plugin.scan();
                break;
            case "openPhoto".toLowerCase():
                plugin.openPhoto && plugin.openPhoto(this.props.params.url);
                break;
            case "openCamera".toLowerCase():
                plugin.openCamera && plugin.openCamera(this.props.params.url);
                break;
            default :
                break;
        }
        return (
            <Text style={{position:"absolute"}}/>
        )
    }
    componentWillUnmount() {
        if (Platform.OS === 'ios') {
            subscription && subscription.remove();
            subResultForUpload && subResultForUpload.remove();
        } else {
        }
    }
}


